<!-- 积分抽奖 -->
<template>
    <div class="divBox">
        <el-card class="box-card">
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="时间范围">
                    <el-date-picker v-model="form.timeRange" type="datetimerange" align="right" value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="开始日期"
                        end-placeholder="结束日期"  >
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="最大">
                    <el-input-number v-model="form.max"></el-input-number>
                </el-form-item>
                <el-form-item label="最小">
                    <el-input-number v-model="form.min"></el-input-number>
                </el-form-item>
                <el-form-item label="抽奖次数">
                    <el-input-number v-model="form.count"></el-input-number>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handlerSubmit">保存</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</template>

<script>
import zbParser from '@/components/FormGenerator/components/parser/ZBParser'
import { configSaveForm, configInfo } from '@/api/systemConfig.js'
import { Debounce } from '@/utils/validate'
export default {
    name: "integralconfig",
    components: { zbParser },
    data() {
        return {
            isShow: false,
            isCreate: 0,
            editData: {},
            form: {},
            formId: 146
        }
    },
    mounted() {
        this.getFormInfo()
    },
    methods: {
        resetForm(formValue) {
            this.editData = {}
        },
        handlerSubmit: Debounce(function () {
            const tempArr = []
            let data = this.form

            for (var key in data) {
                const obj = {}
                obj.name = key
                obj.title = key
                if (data[key] instanceof Array) {
                    obj.value = data[key].toString()
                } else {
                    obj.value = data[key]
                }
                tempArr.push(obj)
            }
            
            const _pram = {
                'fields': tempArr,
                'id': this.formId,
                'sort': 0,
                'status': true
            }
           
            configSaveForm(_pram).then(res => {
                this.getFormInfo()
                this.$message.success('操作成功')
            })
        }),
        // 获取表单详情
        getFormInfo() {
            configInfo({ id: this.formId }).then(res => {
                this.isShow = false
                this.editData = res
                // console.log(res.timeRange);
                this.editData.timeRange = res.timeRange.split(',')

                this.form = this.editData
                this.isCreate = 1
                setTimeout(() => { // 让表单重复渲染待编辑数据
                    this.isShow = true
                }, 80)
            })
        }
    }
}
</script>

<style scoped></style>